package com.mytools.tool.utils;

import java.io.BufferedReader;
import java.io.InputStreamReader;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.telephony.TelephonyManager;

public class SystemUtil {
	
	/**
	 * 获得Assets文件的字符串内容
	 * @param context
	 * @param fileName
	 * @return
	 */
    public static String getFromAssets(Context context, String fileName){ 
        try { 
            InputStreamReader inputReader = new InputStreamReader(context.getResources().getAssets().open(fileName) ); 
            BufferedReader bufReader = new BufferedReader(inputReader);
            String line="";
            String Result="";
            while((line = bufReader.readLine()) != null)
                Result += line;
            return Result;
        } catch (Exception e) { 
            e.printStackTrace(); 
        }
        return "";
    }

	/**
	 * 获得应用版本号
	 * @param context
	 * @return
	 */
	public static int getVerCode(Context context) {
		int verCode = -1;
		try {
			PackageManager packageManager = context.getPackageManager();
			PackageInfo packInfo = packageManager.getPackageInfo(context.getPackageName(), PackageManager.GET_META_DATA);
			verCode = packInfo.versionCode;
		} catch (PackageManager.NameNotFoundException e) {
			e.printStackTrace();
		}
		return verCode;
	}
	/**
	 * 获得应用版本号
	 * @param context
	 * @return
	 */
	public static String getVerName(Context context) {
		String versionName = "";
		try {
			PackageManager packageManager = context.getPackageManager();
			PackageInfo packInfo = packageManager.getPackageInfo(context.getPackageName(), PackageManager.GET_META_DATA);
			versionName = packInfo.versionName;
		} catch (PackageManager.NameNotFoundException e) {
			e.printStackTrace();
		}
		return versionName;
	}
	
	/**
	 * 获取IMSI
	 * @param context
	 * @return
	 */
	public static String getImsi(Context context){
		TelephonyManager tm = (TelephonyManager) context.getSystemService(context.TELEPHONY_SERVICE); 
		return tm.getDeviceId();
	}
    
}
